package com.wenwei.sharebox.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wenwei.sharebox.R;
import com.wenwei.sharebox.activity.GoodsDetailsActivity;
import com.wenwei.sharebox.activity.ReturnMoneyActivity;
import com.wenwei.sharebox.adapter.UserShareAdapter;
import com.wenwei.sharebox.base.BaseFragment;
import com.wenwei.sharebox.base.Constant;
import com.wenwei.sharebox.bean.UserShareBean;
import com.wenwei.sharebox.net.ApiManager;
import com.wenwei.sharebox.net.BaseSubscriber;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/20.
 */
public class ShareBuyFragment extends BaseFragment {
    @Bind(R.id.recycler)
    RecyclerView recycler;
    UserShareAdapter mShareAdapter;
    @Override
    public View initView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.fragment_share_commont, null);
    }

    @Override
    protected void lazyload() {

    }

    @Override
    protected void initEvent() {
        super.initEvent();
        recycler.setLayoutManager(new LinearLayoutManager(mActivity));
        mShareAdapter = new UserShareAdapter(new UserShareAdapter.CallBack() {
            @Override
            public void onItemClick(UserShareBean.DataBean bean) {
//                goActivity(mActivity, GoodsDetailsActivity.class);
                Bundle b1 = new Bundle();
                b1.putSerializable("bean",bean);
                goActivity(mActivity, ReturnMoneyActivity.class,b1);
            }

            @Override
            public void onReturnMoney() {
                goActivity(mActivity, ReturnMoneyActivity.class);
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();
        getUserShareBuy();
    }

    BaseSubscriber<UserShareBean> buySubscriber;
    private void getUserShareBuy(){
        buySubscriber = new BaseSubscriber<UserShareBean>(mActivity) {
            @Override
            public void onSuccess(UserShareBean userShareBean) {
                mShareAdapter.setShareDataList(userShareBean.getData());
                recycler.setAdapter(mShareAdapter);
                mShareAdapter.notifyDataSetChanged();
            }
        };
        ApiManager.getInstance().getBuyAndRent(buySubscriber,1,10, Constant.SHARE_TYPE_BUY);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
